package app.auto.runner.base;

import android.app.Activity;
import android.app.LocalActivityManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import androidx.annotation.Nullable;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;

import java.util.List;

import androidx.viewpager.widget.ViewPager;
import app.auto.runner.ActivityBaseCompact;

public class ToViewActivityCompact extends ActivityBaseCompact {
    private ViewPager pager;
    private List<View> pages;


    LocalActivityManager mLocalActivityManager;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        mLocalActivityManager = new LocalActivityManager((Activity) this, true);
        mLocalActivityManager.dispatchCreate(savedInstanceState);
        super.onCreate(savedInstanceState);
    }

    public View activityToView(Context parent, Intent intent) {
        final Window w = mLocalActivityManager.startActivity(parent.getClass().getName(), intent);
        final View wd = w != null ? w.getDecorView() : null;
        if (wd != null) {
            wd.setVisibility(View.VISIBLE);
            wd.setFocusableInTouchMode(true);
            ((ViewGroup) wd).setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
        }
        return wd;
    }

    @Override
    protected void onPause() {
        super.onPause();
        mLocalActivityManager.dispatchPause(isFinishing());
    }

    @Override
    protected void onResume() {
        super.onResume();
        mLocalActivityManager.dispatchResume();
    }

}
